import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
const app = createApp(App);
//配置全局路径
axios.defaults.baseURL = "http://localhost:8080/app"
//将axios挂载到app对象上
app.config.globalProperties.$axios = axios
//跨域请求中传递cookie
axios.defaults.withCredentials = true


// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
	console.log('响应拦截器：',response);
	if(response.data.code == 50001){
		router.push("/login");
	}
    return response;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  })


import { Button , Tabbar, TabbarItem,Col,Row,Icon} from 'vant'
import 'vant/lib/index.css';
import { Swipe, SwipeItem } from 'vant';
import { List } from 'vant';
import { Notify } from 'vant';
import { showNotify } from 'vant'
import {Card} from 'vant';
import {Popup} from 'vant';
import { SubmitBar } from 'vant';
import { showToast } from 'vant';
import { ContactList } from 'vant';
import { AddressList } from 'vant';
import { AddressEdit } from 'vant';
import { Area } from 'vant';
import { Form, Field, CellGroup } from 'vant';
import { Image as VanImage } from 'vant';
//注册组件
app.use(Button);
app.use(Tabbar);
app.use(TabbarItem);
app.use(Col);
app.use(Row);
app.use(Icon);
app.use(Swipe);
app.use(SwipeItem);
app.use(List);
app.use(Notify);
app.use(showNotify);
app.use(Popup);
app.use(Card);
app.use(SubmitBar);
app.use(showToast)
app.use(ContactList)
app.use(AddressList)
app.use(AddressEdit)
app.use(Area)
app.use(Form);
app.use(Field);
app.use(CellGroup);
app.use(VanImage);

router.beforeEach((to,from,next)=>{
    console.log('路由守卫：',to.path);
    store.state.activeTab=to.path;
    next();
})

app.use(store).use(router).mount('#app')
